define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vppz/kjyl/index' + location.search,
                    add_url: 'vppz/kjyl/add',
                    edit_url: 'vppz/kjyl/edit',
                    del_url: 'vppz/kjyl/del',
                    multi_url: 'vppz/kjyl/multi',
                    table: 'vppz_hospital',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),searchable:false},
                        {field: 'name', title: '医院名称', operate: 'LIKE'},
                        {field: 'avatar', title: '形象照', operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image,searchable:false},
                        {field: 'rank', title:'医院等级',  // 显示转换：将1/2/3转换为文字
                            formatter: function(value, row, index) {
                                const genderMap = {0: '一级', 1: '二级', 2: '三级'};
                                return genderMap[value] || '三级';
                            },
                            // 筛选配置
                            searchList: {
                                '0': '一级',
                                '1': '二级',
                                '2': '三级'
                            },
                            // 筛选操作符（等于）
                            operate: '='},
                        {field: 'label', title:'医院类型', // 显示转换：将1/2/3转换为文字
                            formatter: function(value, row, index) {
                                const genderMap = {0: '综合医院', 1: '专科医院', 2: '中医医院', 3: '妇幼保健院', 4: '康复医院'};
                                return genderMap[value] || '未知';
                            },
                            // 筛选配置
                            searchList: {
                                '0': '综合医院',
                                '1': '专科医院',
                                '2': '中医医院',
                                '3': '妇幼保健院',
                                '4': '康复医院',
                            },
                            // 筛选操作符（等于）
                            operate: '='},
                        //{field: 'province', title: __('Province'), operate: 'LIKE'},
                        {field: 'city', title: '所在地点', operate: 'LIKE'},
                        //{field: 'district', title: __('District'), operate: 'LIKE'},
                        {field: 'address', title: '详细地址', operate: 'LIKE',searchable:false},
                        //{field: 'lat', title: __('Lat'), operate:'BETWEEN'},
                        //{field: 'lng', title: __('Lng'), operate:'BETWEEN'},
                        //{field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'use_switch', title: '是否启用', table: table, formatter: Table.api.formatter.toggle,searchable:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        //{field: 'admin_id', title: __('Admin_id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,

							buttons: [{
                                    name: 'zdks',
                                    title: '重点科室',
									text: '重点科室',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'vppz/hospital_zdks/index',
                                    //callback: function (data) {
                                    //    Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    //}
                                }]
						}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
